package dao;

import abstratos.DAO;
import abstratos.Modelo;
import db.Conexao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Item implements DAO {

    public void inserir(Modelo modelo) {

    }

    public ArrayList<Modelo> consultar() {
       ArrayList<Modelo> listaItem = new ArrayList<Modelo>();

        ResultSet rs = null;

        Conexao conexao = new Conexao();
        conexao.conectar();

        java.sql.Connection con = conexao.getConnection();

        PreparedStatement consultarItem = null;
        String strConsultarItem = "SELECT * FROM item";
        try {
            consultarItem = con.prepareStatement(strConsultarItem);
            rs = consultarItem.executeQuery();

            mvc.modelos.Item oItem;

            while(rs.next()){
                oItem = new mvc.modelos.Item();

                oItem.setItm_vda_seq(rs.getInt(1));
                oItem.setItm_lvr_cod(rs.getInt(2));
                oItem.setItm_qtd(rs.getInt(3));

                listaItem.add(oItem);
            }
            return listaItem;
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
            return null;
        } finally {
            try {
                if (consultarItem != null) {
                    consultarItem.close();
                    con.setAutoCommit(true);
                }
                if (!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException ex) {
                System.out.println(ex.getMessage());
            }
        }
    }



}
